#include <iostream>
using namespace std;

//菱形继承
//动物类
class Animal
{
public:
    int age;
};

//利用虚继承，可以解决菱形继承的问题
//在继承之前 加上关键字 virtual 变成虚继承,共用一份数据
//Animal为虚基类
//羊类
class Sheep:virtual public Animal
{

};

//骆驼类
class Camel:virtual public Animal
{

};

//羊驼类
class Alpaca:public Camel, public Sheep
{

};

void test1()
{
    Alpaca st;
    st.Sheep::age = 18;
    st.Camel::age = 28;
    //当菱形继承，两个父类拥有相同数据，需要加作用域区分
    cout << "st.Sheep::age = " << st.Sheep::age << endl;
    cout << "st.Camel::age = " << st.Camel::age << endl;

    //这份数据我们只要一份即可，菱形继承导致数据有两份，资源浪费
    cout << "st.age = " << st.age << endl;
}

int main()
{
    test1();
    return 0;
}